#pragma once

#include "CControl.h"

class CListItem;
typedef ArrayTmpl<CListItem> ListItemArray;

enum SelecteMode
{
	SelecteModeSingle,
	SelecteModeMultiply,
};
enum ListControlHightLightType
{
	ListControlHightLightTypeItem,
	ListControlHightLightTypeLine,
};

class UI_API CListControl : public CControl
{
public:
	CListControl();
	CListControl(int_32 iX, int_32 iY, int_32 iWidth, int_32 iHeight);
	~CListControl();

public:
	void AddItem(const CTextW & text, void * pUserData = nullptr);
	const ListItemArray & GetItemArray() const;
	void SetSelect(int iIndex, bool bSelected = true);

	void SuspendLayerout();
	void ResumeLayerout();
	bool IsLayeroutSuspended() const;
	virtual void PerformLayerout();
	void SetHightLightType(ListControlHightLightType eHightLightType);

	virtual void SelectItem(int iIndex, bool bSelect) {}

protected:
	void DrawItems(IPaint * pPaint) const;
protected:
	ListItemArray m_arrItems;
	bool m_bSuspendLayerout;
	bool m_bLayerouted;
	ListControlHightLightType m_eHightLightType;

	SelecteMode m_eSelectMode;
	int m_iSelectedIndex;
};

class UI_API CListItem
{
public:
	CListItem()
		: UserData(nullptr), Width(0), Height(0), Color(0), IsValid(false), IsSelected(false)
	{

	}
	CListItem(const CTextW & text, void * pUserData)
		: Text(text), UserData(pUserData), Width(0), Height(0), Color(0), IsValid(false), IsSelected(false)
	{

	}

	CListItem(const CListItem & another)
	{
		Text = another.Text;
		UserData = another.UserData;
		Width = another.Width;
		Height = another.Height;
		Color = another.Color;
		IsValid = another.IsValid;
		IsSelected = another.IsSelected;
	}

	~CListItem() {}
	CListItem & operator = (const CListItem & another)
	{
		Text = another.Text;
		UserData = another.UserData;
		Width = another.Width;
		Height = another.Height;
		Color = another.Color;
		IsValid = another.IsValid;
		IsSelected = another.IsSelected;
		return *this;
	}

	CTextW Text;
	void * UserData;
	int_32 Width;
	int_32 Height;
	uint_32 Color;
	bool IsValid;
	bool IsSelected;
};